home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / DPMI.INC < prev    next >
Text File  |  1995-08-30  |  10KB  |  303 lines

  1. ; MODEL.INC for ASM32/DPMI source code
  2.  
  3. .386
  4.  
  5. .model small
  6.  
  7. DPMI    equ    1
  8.  
  9. ;Structure of parameter table for real mode interrupt and procedure calling.
  10. ;
  11. ;NOTE:- For interrupts, CS:IP,SS:SP & Flags are filled in by the extender.
  12. ;       For far calls, SS:SP & Flags are filled in by the extender.
  13. ;
  14. RealRegsStruc struc
  15. Real_EDI    dd ?    ;EDI
  16. Real_ESI    dd ?    ;ESI
  17. Real_EBP    dd ?    ;EBP
  18.         dd ?    ;Reserved.
  19. Real_EBX    dd ?    ;EBX
  20. Real_EDX    dd ?    ;EDX
  21. Real_ECX    dd ?    ;ECX
  22. Real_EAX    dd ?    ;EAX
  23. Real_Flags    dw ?    ;FLAGS
  24. Real_ES    dw ?    ;ES
  25. Real_DS    dw ?    ;DS
  26. Real_FS    dw ?    ;FS
  27. Real_GS    dw ?    ;GS
  28. Real_IP    dw ?    ;IP
  29. Real_CS    dw ?    ;CS
  30. Real_SP    dw ?    ;SP
  31. Real_SS    dw ?    ;SS
  32. RealRegsStruc ends
  33.  
  34.  
  35. Sys    macro p1
  36. ;
  37. ;Call a system function. Operand supplied is the function number. Use
  38. ;of this macro is not obligatory, use your own version if you want.
  39. ;
  40.     mov    ax,p1
  41.     int    31h
  42.     endm
  43.  
  44. ; Function 000Ah - Create Alias Descriptor:
  45. ;-----------------------------------------------
  46. ;
  47. ;Creates a new data descriptor that has the same base and limit as the
  48. ;specified descriptor.
  49. ;
  50. ;In:
  51. ;  AX     = 000ah
  52. ;  BX     = selector
  53. ;
  54. ;Out:
  55. ;  if successful:
  56. ;  AX     = data selector (alias)
  57. ;
  58. ;  if failed:
  59. ;  AX     = error code:
  60. ;           8011h - descriptor unavailable
  61. ;           8022h - invalid selector
  62. ;
  63. ;Notes:
  64. ;) The selector supplied to the function may be either a data descriptor or
  65. ;  a code descriptor. The alias descriptor created is always an expand-up
  66. ;  writeable data segment.
  67. ;
  68. ;) The descriptor alias returned by this function will not track changes to the
  69. ;  original descriptor.
  70.  
  71. AliasSel    equ    000Ah
  72.  
  73.  
  74. ; Function 0100h - Allocate DOS Memory Block:
  75. ;--------------------------------------------
  76. ;
  77. ; Allocate a block of DOS memory, returning AX real-mode segment and
  78. ; BX selector for allocated block
  79. ;
  80. ; In:  BX = paragraphs to allocate
  81. ; Out: [CF=0] AX = real-mode segment base address
  82. ;             BX = selector for allocated block
  83. ;      [CF=1] AX = error code
  84. ;             BX = size of larges available block in paragraphs
  85. ;
  86.  
  87. GetMemDOS    equ    0100h
  88.  
  89.  
  90. ; Function 0101h - Free DOS Memory Block:
  91. ;----------------------------------------
  92. ;
  93. ; Release a block of DOS (conventional) memory previously allocated with
  94. ; GetMemDOS.
  95. ;
  96. ; In:  DX = Selector of block to free
  97. ; Out: [CF=0] no error
  98. ;      [CF=1] AX = DOS error code
  99. ;
  100. ;Notes:
  101. ;
  102. ;) All descriptors allocated for the memory block are automatically freed
  103. ;  and therefore should not be accessed once the block is freed by this
  104. ;  function.
  105.  
  106. RelMemDOS    equ    0101h
  107.  
  108.  
  109. ; Function 0102h - Resize DOS Memory Block:
  110. ;------------------------------------------
  111. ;
  112. ; Resize a block of DOS (conventional) memory previously allocated with
  113. ; GetMemDOS.
  114. ;
  115. ; In:  BX = New block size in paragraphs
  116. ;      DX = Selector of block to modify
  117. ; Out: [CF=0] no error
  118. ;      [CF=1] AX = DOS error code:
  119. ;             BX = Maximum block size possible in paragraphs
  120. ;
  121. ;Notes:
  122. ;
  123. ;) Growing a memory block is often likely to fail since other DOS block
  124. ;  allocations will prevent increasing the size of the block. Also, if the
  125. ;  size of a block grows past a 64K boundary then the allocation will fail
  126. ;  if the next descriptor in the LDT is  not free.
  127. ;
  128. ResMemDOS    equ    0102h
  129.  
  130.  
  131. ; Function 0300h - Simulate Real Mode Interrupt:
  132. ;-----------------------------------------------------
  133. ;
  134. ;Simulates an interrupt in real mode. The function transfers control to the
  135. ;address specified by the real mode interrupt vector. The real mode handler
  136. ;must return by executing an IRET.
  137. ;
  138. ;In:
  139. ;  AX     = 0300h
  140. ;  BL     = interrupt number
  141. ;  BH     = must be 0
  142. ;  CX     = number of words to copy from the protected mode stack to the real
  143. ;           mode stack
  144. ;  ES:EDI = selector:offset of real mode register data structure in the
  145. ;           following format:
  146. ;
  147. ;           Offset  Length  Contents
  148. ;           00h     4       EDI
  149. ;           04h     4       ESI
  150. ;           08h     4       EBP
  151. ;           0ch     4       reserved, ignored
  152. ;           10h     4       EBX
  153. ;           14h     4       EDX
  154. ;           18h     4       ECX
  155. ;           1ch     4       EAX
  156. ;           20h     2       CPU status flags
  157. ;           22h     2       ES
  158. ;           24h     2       DS
  159. ;           26h     2       FS
  160. ;           28h     2       GS
  161. ;           2ah     2       IP (reserved, ignored)
  162. ;           2ch     2       CS (reserved, ignored)
  163. ;           2eh     2       SP
  164. ;           30h     2       SS
  165. ;
  166. ;Out:
  167. ;  if successful:
  168. ;  ES:EDI = selector offset of modified real mode register data structure
  169. ;
  170. ;  if failed:
  171. ;  AX     = error code:
  172. ;           8012h - linear memory unavailable (stack)
  173. ;           8013h - physical memory unavailable (stack) (DPMI 1.0 only)
  174. ;           8014h - backing store unavailable (stack) (DPMI 1.0 only)
  175. ;           8021h - invalid value (CX too large) (DPMI 1.0 only)
  176. ;
  177. ;Notes:
  178. ;) The CS:IP in the real mode register data structure is ignored by this
  179. ;  function. The appropriate interrupt handler will be called based on the
  180. ;  value passed in BL.
  181. ;
  182. ;) If the SS:SP fields in the real mode register data structure are zero, a
  183. ;  real mode stack will be provided by the host. Otherwise the real mode SS:SP
  184. ;  will be set to the specified values before the interrupt handler is called.
  185. ;
  186. ;) The flags specified in the real mode register data structure will be put on
  187. ;  the real mode interrupt handler's IRET frame. The interrupt handler will be
  188. ;  called with the interrupt and trace flags clear.
  189. ;
  190. ;) Values placed in the segment register positions of the data structure must
  191. ;  be valid for real mode. That is, the values must be paragraph addresses, not
  192. ;  protected mode selectors.
  193. ;
  194. ;) The target real mode handler must return with the stack in the same state
  195. ;  as when it was called. This means that the real mode code may switch stacks
  196. ;  while it is running, but must return on the same stack that it was called
  197. ;  on and must return with an IRET.
  198. ;
  199. ;) When this function returns, the real mode register data structure will
  200. ;  contain the values that were returned by the real mode interrupt handler.
  201. ;  The CS:IP and SS:SP values will be unmodified in the data structure.
  202. ;
  203. ;) It is the caller's responsibility to remove any parameters that were pushed
  204. ;  on the protected mode stack.
  205.  
  206. IntXX        equ    0300h
  207.  
  208.  
  209. ; Function 0501h - Allocate Memory Block:
  210. ;----------------------------------------------
  211. ;
  212. ;Allocates a block of extended memory.
  213. ;
  214. ;In:
  215. ;  AX     = 0501h
  216. ;  BX:CX  = size of block in bytes (must be non-zero)
  217. ;
  218. ;Out:
  219. ;  if successful:
  220. ;  BX:CX  = linear address of allocated memory block
  221. ;  SI:DI  = memory block handle (used to resize and free block)
  222. ;
  223. ;  if failed:
  224. ;  AX     = error code:
  225. ;           8010h - internal resource unavailable (stack) (XMS only)
  226. ;           8012h - linear memory unavailable (DPMI 1.0/VCPI only)
  227. ;           8013h - physical memory unavailable
  228. ;           8014h - backing store unavailable (DPMI 1.0 only)
  229. ;           8016h - handle unavailable (DPMI 1.0/XMS only)
  230. ;           8021h - invalid value (BX:CX = 0)
  231. ;
  232. ;Notes:
  233. ;) The allocated block is guaranteed to have at least paragraph alignment.
  234. ;
  235. ;) This function does not allocate any descriptors for the memory block. It is
  236. ;  the responsibility of the client to allocate and initialize any descriptors
  237. ;  needed to access the memory with additional function calls.
  238. ;
  239. ;) The allocations by this function could be paragraph, kilobyte, or page
  240. ;  aligned. That is, the value you request could be rounded up to the next
  241. ;  paragraph, kilobyte, or page value.
  242.  
  243. GetMem        equ    0501h
  244.  
  245.  
  246. ; Function 0502h - Free Memory Block:
  247. ;------------------------------------------
  248. ;
  249. ;Frees a memory block previously allocated with the Allocate Memory Block
  250. ;function (0501h).
  251. ;
  252. ;In:
  253. ;  AX     = 0502h
  254. ;  SI:DI  = memory block handle
  255. ;
  256. ;Out:
  257. ;  if failed:
  258. ;  AX     = error code:
  259. ;           8010h - internal resource unavailable (stack) (XMS only)
  260. ;           8023h - invalid handle
  261. ;
  262. ;Notes:
  263. ;) No descriptors are freed by this call. It is the client's responsibility to
  264. ;  free any descriptors that it previously allocated to map the memory block.
  265. ;  Descriptors should be freed before memory blocks.
  266.  
  267. RelMem        equ    0502h
  268.  
  269.  
  270. ; Function 0503h - Resize Memory Block:
  271. ;--------------------------------------------
  272. ;
  273. ;Changes the size of a memory block previously allocated with the Allocate
  274. ;Memory Block function (0501h).
  275. ;
  276. ;In:
  277. ;  AX     = 0503h
  278. ;  BX:CX  = new size of block in bytes (must be non-zero)
  279. ;  SI:DI  = memory block handle
  280. ;
  281. ;Out:
  282. ;  BX:CX  = new linear address of memory block
  283. ;  SI:DI  = new memory block handle
  284. ;
  285. ;  if failed:
  286. ;  AX     = error code:
  287. ;           8010h - internal resource unavailable (stack) (XMS only)
  288. ;           8012h - linear memory unavailable (DPMI 1.0/VCPI only)
  289. ;           8013h - physical memory unavailable
  290. ;           8014h - backing store unavailable (DPMI 1.0 only)
  291. ;           8016h - handle unavailable (DPMI 1.0/XMS only)
  292. ;           8021h - invalid value (BX:CX = 0)
  293. ;           8023h - invalid handle
  294. ;
  295. ;Notes:
  296. ;) After this function returns successfully, the previous handle for the memory
  297. ;  block is invalid and should not be used anymore.
  298. ;
  299. ;) It is the client's responsibility to update any descriptors that map the
  300. ;  memory block with the new linear address after resizing the block.
  301.  
  302. ResMem        equ    0503h
  303.